import { createSlice } from "@reduxjs/toolkit"
import dayjs from "dayjs"
export const counterSlice = createSlice({
  name: "counter",
  initialState: {
    date: dayjs().format("YYYY-MM-DD"),
  },
  reducers: {
    // 前一天
    beforeDate(state, { payload }) {
      state.date = dayjs(state.date).add(payload, "day").format("YYYY-MM-DD")
    },
    // 后一天
    afterDate(state, { payload }) {
      state.date = dayjs(state.date).add(payload, "day").format("YYYY-MM-DD")
    },
  },
})
// 每个 case reducer 函数会生成对应的 Action creators
export const { beforeDate, afterDate } = counterSlice.actions

export default counterSlice.reducer
